草庐IT

django.core.exceptions.ImproperlyConfigured : name must be an instance of basestring

全部标签

c# - PrintDocument.Print 导致 Win32Exception 操作成功完成

我正在尝试在C#.NET3.5应用程序中打印到网络打印机并出现此异常:Theoperationcompletedsuccessfully是什么原因造成的,如何解决?System.ComponentModel.Win32Exception:TheoperationcompletedsuccessfullyatSystem.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()atSystem.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettingspageSettings)at

c# - .NET Core 中 HttpListener 的模拟是什么

我正在将应用程序从.NET4移植到.NETCore,但找不到HttpListener类的模拟ErrorCS0246Thetypeornamespacename'HttpListener'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?)更新1privatereadonlyHttpListener_httpListener;if(!HttpListener.IsSupported){thrownewNotSupportedException("TheHttpServercannotrunonthisope

c# - IFormFile 始终为 null(带有 MVC/Razor 的 ASP.NET Core)

我有一个ASP.NETCoreMVC应用试图上传IFormFile。但是,IFormFile始终为空。我发现的其他解决方案都没有解决这个问题。我做错了什么?模型publicclassEmailForm{[Display(Name="Addapicture")][DataType(DataType.Upload)][FileExtensions(Extensions="jpg,png,gif,jpeg,bmp,svg")]publicIFormFileSubmitterPicture{get;set;}}ControllerpublicasyncTaskContribute([Bind(

c# - 如何在 asp.net core 中获取 IConfiguration 的实例?

我制作了一个单元测试项目来测试我的webapi,我需要初始化一个Controller,问题是在构造函数中它接收到一个IConfiguration,它由依赖注入(inject)提供并且工作正常。但是当我想手动初始化它时,我没有办法得到这个实例。我正在尝试从同一项目内部的单元测试项目初始化它。Controller看起来像:publicController(IConfigurationconfiguration){_configuration=configuration;} 最佳答案 我可能应该从以下声明开始:在.NetCore应用程序中

c# - .NET Core 使用配置绑定(bind)到带有数组的选项

使用.NETCoreMicrosoft.Extensions.Configuration是否可以将配置绑定(bind)到包含数组的对象?ConfigurationBinder有一个方法BindArray,所以我认为它会起作用。但是当我尝试它时,我得到了一个异常(exception):System.NotSupportedException:ArrayConvertercannotconvertfromSystem.String.这是我精简后的代码:publicclassTest{privateclassExampleOption{publicint[]Array{get;set;}}[

c# - 如何在 .NET Core 2.1 中使用 String.Create 的示例

有谁知道这个方法是如何使用的?文档有点“轻”!publicstaticstringCreate(intlength,TStatestate,System.Buffers.SpanActionaction);https://learn.microsoft.com/en-us/dotnet/api/system.string.create?view=netcore-2.2 最佳答案 String.Create()method需要三样东西:决赛length的字符串。您必须事先知道这一点,因为该方法需要它安全为Span创建一个内部固定长度缓

c# - 如何向 ASP.NET Core 添加自定义角色

我找到了thisanswer但它似乎不适合我的ASPNetCore项目。我想了解的事情:如何添加自定义角色。我什至直接查看了我的MySQL数据库(表aspnetroles),但我不知道使用什么作为Id和ConcurrencyStamp。将这些新角色植入数据库的代码放在哪里:在Startup中?在AccountController下的Register中?如何将这个新角色与用户关联起来?我什至查看了表格,但我不知道如何分配数据(没有user2role或aspnetusers.role_id)。 最佳答案 您可以通过在启动类中创建一个Cr

c# - 在 ASP.NET Core 2.0 中将 DataTable 转换为 IEnumerable<T>

我需要从我从另一个系统收到的作为输入的DataTable生成一个“IEnumerable”。以下代码适用于ASP.NET4.6.1。publicstaticIEnumerableStaffAssignmentsUsingStoredProcedure(System.Data.DataTabledataTable){vardata=dataTable.AsEnumerable().Select(row=>newUserAssignmentDto{Id=((string)row["AssignmentNumber"]),Position=(string)row["EsrPositionTi

c# - ASP.NET Core - 自定义模型验证

在MVC中,当我们将模型发布到操作时,我们执行以下操作以根据该模型的数据注释验证模型:if(ModelState.IsValid)如果我们将属性标记为[Required],则ModelState.IsValid将验证该属性是否包含值。我的问题:如何手动构建和运行自定义验证器?附言我只是在谈论后端验证器。 最佳答案 在.NETCore中,您可以简单地创建一个继承自ValidationAttribute的类。您可以在ASP.NETCoreMVCDocs中查看完整详细信息.这是直接从文档中获取的示例:publicclassClassicM

c# - 奇怪的系统.__佳能异常(exception)

我有一个使用单例类的Windows服务ThreadQueue.当服务启动时,它会调用ThreadQueue.Start()然后,此类接受任务并将其排队,将并发性限制为可配置的线程数。ThreadQueue.Start()在服务启动时被调用一次。有时,服务运行几个小时后,我会收到以下异常:Application:myservice.exeFrameworkVersion:v4.0.30319Description:Theprocesswasterminatedduetoanunhandledexception.ExceptionInfo:System.NullReferenceExcep